home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
- #include <Processes.h>
- #include <Script.h>
- #include <Folders.h>
-
-
-
- /*
-
-
- Directions for building word fixer:
-
- • To make an extension to go on the loadset, change the file type to 'appe'. It
- will run in quiet mode, without any feedback.
-
- • To make an application for users to run (for example if they're copying it off
- the keyserver) change the file type to 'APPL'. It checks a few more things,
- makes sure Word isn't running, and also kills the RegDBs (which the appe doesn't do).
- It also posts a notification as to whether it ran successfully or not.
-
-
- ps: don't look too carefully at this code, most of it is what Ed whipped up on
- an emergency basis and i only made a few minor cleanups. it's more than a little
- bit skanky. have fun.
-
- -drew 7/12/96
-
-
- */
-
-
-
- // global flag -- are we a real application?
- Boolean isAPPL;
-
-
-
-
-
-
-
-
-
- Boolean FindAProcess (OSType signature, ProcessSerialNumber
- *process,ProcessInfoRec *infoRec,
- FSSpecPtr aFSSpecPtr);
-
- Boolean FindAProcess (OSType signature, ProcessSerialNumber *process,
- ProcessInfoRec *infoRec, FSSpecPtr
- aFSSpecPtr)
- {
- process->highLongOfPSN = 0;
- process->lowLongOfPSN = kNoProcess; // start from the beginning
-
- infoRec->processInfoLength = sizeof(ProcessInfoRec);
- infoRec->processName = (StringPtr) NewPtr(32);
- infoRec->processAppSpec = aFSSpecPtr;
-
- while (!GetNextProcess(process)) {
-
- if (!GetProcessInformation(process, infoRec) ) {
- if ( (infoRec->processType == (long) 'APPL') &&
- (infoRec->processSignature == signature) )
- return TRUE; // found the process
-
- }
- } // while
-
- return FALSE;
- }
-
-
-
- // function prototype
- long GetMicrosoftDirID(void);
- long GetMicrosoftDirID(void)
- {
- #define kMaxMatches 1 // find up to 1 match in one pass
- #define kOptBufferSize 16384 // use a 16k search cache for speed
-
- OSErr gErr; // error variable
- HParamBlockRec gPb; // parameter block for PBCatSearch
- FSSpec gTheResults[kMaxMatches]; // put matches here
- CInfoPBRec gSpec1; // search criteria, part 1
- CInfoPBRec gSpec2; // search criteria, part 2
- char gBuffer[kOptBufferSize]; // search cache
- Str255 gFileName; // name of string to look for
- short vRefNum = -1; // volume on which to search
- short loopy,done; // set to true when all matches done
-
-
- // search for temp
- // first use strcpy to copy string to gFileName, then convert to pascal style
- // string for toolbox use
- strcpy ((char *)gFileName, "MS Spelling");
- CtoPstr((char*)gFileName);
-
- gPb.csParam.ioCompletion = nil; // no completion routine
- gPb.csParam.ioNamePtr = nil; // no volume name; use vRefNum
- gPb.csParam.ioVRefNum = vRefNum; // volume to search
- gPb.csParam.ioMatchPtr = gTheResults; // points to results buffer
- gPb.csParam.ioReqMatchCount = kMaxMatches; // number of matches
-
- // search partial name, file attributs, and creation date
- gPb.csParam.ioSearchBits = fsSBPartialName + fsSBFlAttrib;
- gPb.csParam.ioSearchInfo1 = &gSpec1; // points to first criteria set
- gPb.csParam.ioSearchInfo2 = &gSpec2; // points to second criteria set
- gPb.csParam.ioSearchTime = -1; // don't time out on searches
- gPb.csParam.ioCatPosition.initialize = 0; // set hint to 0
- gPb.csParam.ioOptBuffer = gBuffer; // point to search cache
- gPb.csParam.ioOptBufSize = kOptBufferSize; // size of search cache
-
- gSpec1.hFileInfo.ioNamePtr = gFileName; // point to string to find
- gSpec1.hFileInfo.ioFlAttrib = 0x00; // clear bit 4 to ask for files
-
- gSpec2.hFileInfo.ioNamePtr = nil; // set to nil
- gSpec2.hFileInfo.ioFlAttrib = 0x10; // set mask for bit 4
-
- done = 0;
- do{
- gErr = PBCatSearchSync((CSParam*)&gPb); // get some files
- done = (gErr == eofErr); // eofErr returned when all done
- if (((gErr == noErr) || done) && (gPb.csParam.ioActMatchCount > 0) )
- for ( loopy = 0; loopy < gPb.csParam.ioActMatchCount; loopy++) {
- // report all matches found
- return gTheResults[loopy].parID;
- }
- }while(!done);
-
- return 0L;
- }
-
-
- void GetHardDiskName(StringPtr name);
- void GetHardDiskName(StringPtr name)
- {
- CInfoPBRec pb;
-
- pb.dirInfo.ioCompletion = nil;
- pb.dirInfo.ioNamePtr = name;
- pb.dirInfo.ioVRefNum = -1;
- pb.dirInfo.ioFDirIndex = -1;
- pb.dirInfo.ioDrDirID = 2;
- PBGetCatInfo(&pb,false);
- }
-
-
-
-
- Boolean notificationDone = false;
-
- pascal void ErrorNotifyDone( NMRec *nmr );
- pascal void ErrorNotifyDone( NMRec *nmr )
- {
- long oldA5 = SetA5( nmr->nmRefCon );
-
- NMRemove( nmr );
- notificationDone = true;
-
- SetA5( oldA5 );
- }
-
-
- void ErrorNotify( short id );
- void ErrorNotify( short id )
- {
- NMRecPtr nmr;
- Str255 string;
- EventRecord ev;
- NMUPP nmupp;
-
- if (!isAPPL)
- return;
-
- GetIndString( string, 128, id );
-
- nmr = (NMRecPtr) NewPtrSysClear( sizeof(NMRec) );
- if (!nmr) return;
-
- nmr->qType = nmType;
- nmr->nmStr = string;
- nmr->nmResp = (nmupp = NewNMProc(ErrorNotifyDone));
- nmr->nmRefCon = GetCurrentA5();
-
- if (NMInstall(nmr))
- return;
-
- while (!notificationDone)
- WaitNextEvent( everyEvent, &ev, 60, nil );
-
- DisposeRoutineDescriptor( nmupp );
- DisposePtr( (Ptr)nmr );
- }
-
-
- void MicrosoftProgrammersAreIdiots( Handle data, char *hdName );
- void MicrosoftProgrammersAreIdiots( Handle data, char *hdName )
- {
- char c[200];
- short len, index, copy;
-
- len = sprintf(c,"%s",hdName);
- c[len++] = 6;
- c[len++] = 7;
- c[len++] = 8;
-
- for (copy = 0,index = 0;index<GetHandleSize(data);index++)
- {
- if (copy)
- c[len++] = ((char*)(*data))[index];
-
- if (((char*)(*data))[index] == 8)
- copy = 1;
- }
-
- c[len++] = 0;
- CtoPstr(c);
- SetHandleSize(data,1+c[0]); /* IM II pg 34 */
- BlockMove(c,*data,1+c[0]);
- ChangedResource(data);
- WriteResource(data);
- ReleaseResource(data);
- }
-
-
-
-
- Boolean AmIReal( void );
- Boolean AmIReal( void )
- {
- ProcessSerialNumber myPSN;
- ProcessInfoRec info;
- FSSpec spec;
- FInfo finfo;
-
- GetCurrentProcess( &myPSN );
-
- info.processInfoLength = sizeof(info);
- info.processName = nil;
- info.processAppSpec = &spec;
- GetProcessInformation( &myPSN, &info );
-
- FSpGetFInfo( &spec, &finfo );
-
- return ( finfo.fdType == 'APPL' );
- }
-
-
-
- void main( void )
- {
- long dirID;
- FSSpec spec;
- short prefVRef;
- long prefDirID,index;
- char hdName[32];
- char c[256];
- short len,fRefNum,copy;
- Handle data;
-
-
- isAPPL = AmIReal();
-
-
- GetHardDiskName((StringPtr)hdName);
- PtoCstr((StringPtr)hdName);
-
- if (isAPPL)
- {
- ProcessSerialNumber psn;
- ProcessInfoRec procInfo;
- if (FindAProcess('MSWD',&psn,&procInfo,&spec))
- {
- ErrorNotify( 2 );
- ExitToShell();
- }
- }
-
-
- dirID = GetMicrosoftDirID();
- if (!dirID)
- {
- ErrorNotify( 1 );
- ExitToShell();
- }
-
- FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,&prefVRef,&prefDirID); /* IM VI chap. 9 pg 44 */
-
- /*
- // delete the regDBs -- this stopped being necessary (in fact it was bad)
- // after i wrote the Microsoft Installer Patch.
-
- if (isAPPL)
- {
- FSMakeFSSpec(prefVRef,prefDirID,"\pRegistration Database",&spec);
- FSpDelete(&spec);
-
- FSMakeFSSpec(prefVRef,prefDirID,"\pPPC Registration Database",&spec);
- FSpDelete(&spec);
- }
- */
-
- if (FSMakeFSSpec(prefVRef,prefDirID,"\pWord Settings (6)",&spec))
- FSpCreateResFile(&spec,'MSWD','pref',smSystemScript);
-
- fRefNum = FSpOpenResFile(&spec,fsRdWrPerm);
- if (fRefNum != -1)
- {
- //////////////////////////////////
-
- data = Get1NamedResource('STR ',"\pMicrosoft Word:TOOLS-PATH");
- if (data)
- RmveResource(data);
-
- len = sprintf(c,"%s",hdName);
- c[len++] = 6;
- c[len++] = 7;
- c[len++] = 8;
- c[len++] = 0;
- sprintf(c+strlen(c),"%lx",dirID);
- CtoPstr(c);
- data = NewHandle(c[0]+1);
- BlockMove(c,*data,c[0]+1);
-
- AddResource(data,'STR ',Unique1ID('STR '),"\pMicrosoft Word:TOOLS-PATH");
- WriteResource(data);
- ReleaseResource(data);
-
- //////////////////////////////////
-
- data = Get1NamedResource('STR ',"\pMicrosoft Word:INI-PATH");
- if (data)
- MicrosoftProgrammersAreIdiots( data, hdName );
-
- data = Get1NamedResource('STR ',"\pMicrosoft Word:DOC-PATH");
- if (data)
- MicrosoftProgrammersAreIdiots( data, hdName );
-
- data = Get1NamedResource('STR ',"\pMicrosoft Word:WORKGROUP-DOT-PATH");
- if (data)
- MicrosoftProgrammersAreIdiots( data, hdName );
-
- data = Get1NamedResource('STR ',"\pMicrosoft Word:PICTURE-PATH");
- if (data)
- MicrosoftProgrammersAreIdiots( data, hdName );
-
- data = Get1NamedResource('STR ',"\pMicrosoft Word:STARTUP-PATH");
- if (data)
- MicrosoftProgrammersAreIdiots( data, hdName );
-
- data = Get1NamedResource('STR ',"\pMicrosoft Word:AUTOSAVE-PATH");
- if (data)
- MicrosoftProgrammersAreIdiots( data, hdName );
-
- data = Get1NamedResource('STR ',"\pMicrosoft Word:USER-DOT-PATH");
- if (data)
- MicrosoftProgrammersAreIdiots( data, hdName );
-
- CloseResFile(fRefNum);
-
- ErrorNotify( 4 );
- }
- else
- {
- ErrorNotify( 3 );
- ExitToShell();
- }
- }
-
-
-
-